package com.xmall.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.xmall.define.base.BaseEntity;

import java.util.Collections;

/**
 * 代码生成器
 */
public class Generator {

    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://192.168.100.110:3306/xmall-sys?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true", "root", "123456")
        .globalConfig(builder -> {
            builder.author("xmall") // 设置作者
//                    .enableSwagger() // 开启 swagger 模式
                    .fileOverride() // 覆盖已生成文件
                    .outputDir("D://JavaProjects//generator"); // 指定输出目录
        })
        .dataSourceConfig(builder -> builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
            return typeRegistry.getColumnType(metaInfo);

        }))
        .packageConfig(builder -> {
            builder.parent("com.xmall") // 设置父包名
                    .moduleName("sys") // 设置父包模块名
                    .pathInfo(Collections.singletonMap(OutputFile.xml, "D://JavaProjects//generator")); // 设置mapperXml生成路径
        })
        .strategyConfig(builder -> {
            builder.controllerBuilder().enableRestStyle();
            builder.mapperBuilder().enableMapperAnnotation();
            builder.entityBuilder().enableLombok()
                    .superClass(BaseEntity.class).disableSerialVersionUID()
                    .addIgnoreColumns("create_time", "update_time", "is_deleted");
            builder.addInclude("operate_log"); // 设置需要生成的表名
        })
        .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
        .execute();
    }
}
